<?php
if (!defined('IN_CONTEXT')) die('access violation error!');
?>
<script type="text/javascript">
<!--
function delete_user(u_id)
{
	if (confirm("Do you want to delete this user?")) 
	{
		_ajax_request("user", 
		        "doDeleteUser", 
		        {
		            id: u_id
		        }, 
		        on_delete_success, 
		        on_delete_failure);
	}
}

function on_delete_success(response)
{
	response1 = eval("("+response+")");
	var stat = document.getElementById("stat");
	if(response1.result == 'ok')
	{
		alert(response1.sucmsg);
		stat.innerHTML = "OK，正在重定向......";
		reloadPage();
	}
	else if(response1.result == 'error')
	{
		stat.innerHTML = response1.errmsg;
	}
}

function on_delete_failure(response)
{
	var stat = document.getElementById("stat");
	stat.innerHTML = response;
}
//-->
</script>
<style type="text/css">
table td {
	 text-align:left;
}
table {
	margin-top:20px;
}
</style>
<div id="stat" style="display:none;"></div>
<table width="100%" border="0" cellpadding="2" cellspacing="0" bordercolor="#4c4c4c">
	<tr>
		<td>序号</td>
		<td>用户名</td>
		<td>角色</td>
		<td>电子邮件</td>
		<td>电话</td>
		<td>操作</td>
	</tr>
<?php
if($flag_showAll)
{
	$i = 1;
	foreach($res_arr as $v)
	{
		$tmp_str = '';
		$tmp_arr = explode(',',$v['u_role']);
		foreach($tmp_arr as $v1)
		{
			$tmp_str .= $rights[$v1].',';
		}
		$tmp_str = substr($tmp_str,0,strlen($tmp_str)-1);
		
		echo "<tr>";
		if($v['u_name'] == 'admin')//admin不允许
		{
			echo "<td>$i</td><td>{$v['u_name']}</td><td>$tmp_str</td><td>{$v['u_email']}</td><td>{$v['u_cellphone']}</td><td><a title='查看' href='index.php?_m=user&_a=viewUserPage&u_id={$v['u_id']}'><img style='border:none;' src='./images/view.gif'/></a></td>";
		}
		else
		{
			echo "<td>$i</td><td>{$v['u_name']}</td><td>$tmp_str</td><td>{$v['u_email']}</td><td>{$v['u_cellphone']}</td><td><a href='index.php?_m=user&_a=editUserPage&u_id={$v['u_id']}' title='编辑'><img style='border:none;' src='./images/edit.gif'/></a>&nbsp;<a href='#' title='删除' onclick='delete_user(\"{$v['u_id']}\");'><img style='border:none;' src='./images/cross.gif'/></a></td>";
		}
		echo "</tr>";
		$i++;
	}
}
else
{
	echo "<tr>";
	echo "<td>$i</td><td>{$res_arr['u_name']}</td><td>{$res_arr['u_role']}</td><td>{$res_arr['u_email']}</td><td>{$res_arr['u_cellphone']}</td><td><a href='index.php?_m=user&_a=editUserPage&u_id={$res_arr['u_id']}'>编辑</a></td>"; 
	echo "</tr>";
}
?>
</table>